package com.xcjh.base.dto;

import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

public enum Status {

    SUCCESS(0, "success", "成功"),
    ERROR(-1, "error", "失败"),
    NO_LOGIN(10, "error", "未登录,请登录后再试."),
    LOGIN_TIME_OUT(11, "error", "登录信息以过期.请重新登录后再试."),


    INTERNAL_SERVER_ERROR_ARGS(10000, "Internal Server Error: {0}", "服务端异常: {0}"),
    REQUEST_PARAMS_NOT_VALID_ERROR(10001, "request parameter {0} is not valid", "请求参数[{0}]无效"),
    ORDRER_HAS_RUNNING(10061, "order {0} has running instance", "订单{0}已经提交过，请勿重复提交"),
    USER_NAME_NULL(10004,"user name is null", "用户名不能为空"),
    USER_NOT_EXIST(10010, "user {0} not exists", "用户[{0}]不存在"),
    USER_NAME_PASSWD_ERROR(10013,"user name or password error", "用户名或密码错误"),
    IP_IS_EMPTY(10125,"ip is empty", "IP地址不能为空"),
    USER_NO_OPERATION_PROJECT_PERM(30002, "user {0} is not has project {1} permission", "当前用户[{0}]没有[{1}]功能的操作权限"),
    ;

    private final int code;
    private final String enMsg;
    private final String zhMsg;

    Status(int code, String enMsg, String zhMsg) {
        this.code = code;
        this.enMsg = enMsg;
        this.zhMsg = zhMsg;
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        if (Locale.SIMPLIFIED_CHINESE.getLanguage().equals(LocaleContextHolder.getLocale().getLanguage())) {
            return this.zhMsg;
        } else {
            return this.enMsg;
        }
    }
}
